//
//  TeamInfoVO.m
//  GolfFriend
//
//  Created by Vescky on 13-11-26.
//  Copyright (c) 2013年 vescky.org. All rights reserved.
//

#import "TeamInfoVO.h"
#import <objc/runtime.h>

@implementation TeamInfoVO

@synthesize teamId,teamName,area,createTime,teamLeader,motto,story,avatar,message;
@synthesize teamAdmins,teamMembers,banTalkList,blackList;

- (id)init{
    self = [super init];
    
    return self;
}

- (id)copyWithZone:(NSZone *)zone {
    id copy = [[[self class] alloc] init];
    if (copy) {
        [copy setTeamId:self.teamId];
        [copy setTeamName:self.teamName];
        [copy setArea:self.area];
        [copy setCreateTime:self.createTime];
        [copy setTeamLeader:self.teamLeader];
        [copy setMotto:self.motto];
        [copy setStory:self.story];
        [copy setAvatar:self.avatar];
        [copy setMessage:self.message];
        [copy setTeamAdmins:self.teamAdmins];
        [copy setTeamMembers:self.teamMembers];
        [copy setBanTalkList:self.banTalkList];
        [copy setBlackList:self.blackList];
        
    }
    return copy;
}

- (NSDictionary *)toDictionary
{
    NSMutableDictionary *dictionaryFormat = [NSMutableDictionary dictionary];
    //  取得当前类类型
    Class cls = [self class];
    
    unsigned int ivarsCnt = 0;
    //　获取类成员变量列表，ivarsCnt为类成员数量
    Ivar *ivars = class_copyIvarList(cls, &ivarsCnt);
    
    //　遍历成员变量列表，其中每个变量都是Ivar类型的结构体
    for (const Ivar *p = ivars; p < ivars + ivarsCnt; ++p)
    {
        Ivar const ivar = *p;
        //　获取变量名
        NSString *key = [NSString stringWithUTF8String:ivar_getName(ivar)];
        // 若此变量未在类结构体中声明而只声明为Property，则变量名加前缀 '_'下划线
        // 比如 @property(retain) NSString *abc;则 key == _abc;
        //　获取变量值
        id value = [self valueForKey:key];
        //　取得变量类型
        // 通过 type[0]可以判断其具体的内置类型
        //        const char *type = ivar_getTypeEncoding(ivar);
        if (value)
        {
            [dictionaryFormat setObject:value forKey:key];
        }
    }
    
    return dictionaryFormat;
    
}

- (void)dictionaryToTeamInfoVO:(NSDictionary*)dict {
    [self setTeamId:[dict objectForKey:@"teamId"]];
    [self setTeamName:[dict objectForKey:@"teamName"]];
    [self setArea:[dict objectForKey:@"area"]];
    [self setCreateTime:[dict objectForKey:@"createTime"]];
    [self setTeamLeader:[dict objectForKey:@"teamLeader"]];
    [self setMotto:[dict objectForKey:@"motto"]];
    [self setStory:[dict objectForKey:@"story"]];
    [self setAvatar:[dict objectForKey:@"avatar"]];
    [self setMessage:[dict objectForKey:@"message"]];
    [self setTeamAdmins:[dict objectForKey:@"teamAdmins"]];
    [self setTeamMembers:[dict objectForKey:@"teamMembers"]];
    [self setBanTalkList:[dict objectForKey:@"banTalkList"]];
    [self setBlackList:[dict objectForKey:@"blackList"]];
}

@end
